package com.akuhome.resource.controller;

import com.akuhome.resource.entity.User;
import com.akuhome.resource.service.entity.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/curId")
    public Object getCurrentUserId(){
        User user = userService.getCurrentUser();
        return user.getId();
    }

    @PostMapping("/status")
    public Object updateUserStatus(Integer userId,Boolean enable){
        this.userService.updateUserStatus(userId,enable);
        return null;
    }
    @GetMapping
    public Object findAllUser(){
        return userService.findAllUser();
    }
    @PostMapping
    public Object registerUser(@Validated @RequestBody User user, BindingResult bindingResult){
        userService.register(user);
        return null;
    }
}
